package com.ruoyi.system.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.domain.AppDynamic;
import com.ruoyi.system.domain.AppDynamicMsg;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 动态Mapper接口
 *
 * @author ruoyi
 * @date 2023-02-27
 */
public interface AppDynamicMapper extends BaseMapper<AppDynamic> {
    /**
     * 查询动态
     *
     * @param id 动态主键
     * @return 动态
     */
    public AppDynamic selectAppDynamicById(Long id);

    /**
     * 查询动态列表
     *
     * @param appDynamic 动态
     * @return 动态集合
     */
    public List<AppDynamic> selectAppDynamicList(AppDynamic appDynamic);

    /**
     * 新增动态
     *
     * @param appDynamic 动态
     * @return 结果
     */
    public int insertAppDynamic(AppDynamic appDynamic);

    /**
     * 修改动态
     *
     * @param appDynamic 动态
     * @return 结果
     */
    public int updateAppDynamic(AppDynamic appDynamic);

    /**
     * 删除动态
     *
     * @param id 动态主键
     * @return 结果
     */
    public int deleteAppDynamicById(Long id);

    /**
     * 批量删除动态
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAppDynamicByIds(Long[] ids);

    @Update("update app_dynamic d set d.like_count = (d.like_count + 1) " + "where d.id = #{dynamicId}")
    void addLikeCount(@Param("dynamicId") Long dynamicId);

    @Update("update app_dynamic d " + "set d.comment_count = (d.comment_count + 1) " + "where d.id = #{dynamicId}")
    void addCommentCount(@Param("dynamicId") Long dynamicId);

    @Update("update app_dynamic d " + "set d.comment_count = (d.comment_count - #{count}) " + "where d.id = #{dynamicId}")
    void reduceCommentCount(@Param("dynamicId") Long dynamicId, @Param("count") int count);
}
